package com.dingwei.superiordiary.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.bean.SetStateBean;
import com.dingwei.superiordiary.mvp.presenter.OtherSetPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.ColumValue;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author 南柯一梦丶
 *         Created time 2018/10/22.
 *         Personal signature 余生还长 何必慌张
 *         Page description :
 *         .::::.
 *         .::::::::.
 *         :::::::::::
 *         ..:::::::::::'
 *         '::::::::::::'
 *         .::::::::::
 *         '::::::::::::::..
 *         ..::::::::::::.
 *         ``::::::::::::::::
 *         ::::``:::::::::'        .:::.
 *         ::::'   ':::::'       .::::::::.
 *         .::::'      ::::     .:::::::'::::.
 *         .:::'       :::::  .:::::::::' ':::::.
 *         .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *         ...:::           ::::::::::::'              ``::.
 *         ```` ':.          ':::::::::'                  ::::..
 *         '.:::::'                    ':'````..
 */
public class OtherSetActivity extends BaseActivity implements Contract.OtherView {

    OtherSetPresenter otherSetPresenter = new OtherSetPresenter(this);
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.img_auto_play_video)
    ImageView imgAutoPlayVideo;
    @Bind(R.id.img_add_watermark)
    ImageView imgAddWatermark;
    SetStateBean bean;
    @Override
    public void setData(SetStateBean bean) {
        this.bean = bean;
        if (bean.data.upload_img.equals("1")) {
            imgAddWatermark.setImageResource(R.mipmap.ic_set_open);
        } else {
            imgAddWatermark.setImageResource(R.mipmap.ic_set_close);
        }
    }


    @Override
    public void settingUploadImgSuccess() {
        otherSetPresenter.initData();
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_other_set;
    }

    @Override
    protected void initData() {
        if (BaseActivity.value.getAutoPlayVideo() != ColumValue.NO) {

            imgAutoPlayVideo.setImageResource(R.mipmap.ic_set_open);
        } else {
            imgAutoPlayVideo.setImageResource(R.mipmap.ic_set_close);
        }
        otherSetPresenter.initData();
    }

    @Override
    protected void initView() {
        tvTitle.setText("其他设置");
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.img_auto_play_video, R.id.img_add_watermark})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.img_auto_play_video:
                if (BaseActivity.value.getAutoPlayVideo() == ColumValue.NO) {
                    imgAutoPlayVideo.setImageResource(R.mipmap.ic_set_open);
                    BaseActivity.value.setAutoPlayVideo(ColumValue.NETWORK);
                } else {
                    imgAutoPlayVideo.setImageResource(R.mipmap.ic_set_close);
                    BaseActivity.value.setAutoPlayVideo(ColumValue.NO);
                }
                break;
            case R.id.img_add_watermark:
                if (bean.data.upload_img.equals("1")){
                    otherSetPresenter.settingUploadImg("0");
                }else {
                    otherSetPresenter.settingUploadImg("1");
                }
                break;
        }
    }
}
